home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / Adjust.ieb next >
Encoding:
Text File  |  1997-02-02  |  5.0 KB  |  188 lines

  1. /*
  2. ** $VER: Adjust.ieb 1.2, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten 
  5. ** 19/1 1997 Stockholm/Sweden
  6. **
  7. ** Adjust slices of image vertically or horizontally.
  8. ** Based on the script Adjust.rexx 1.2.
  9. */
  10.  
  11. options results
  12. signal on error
  13.  
  14. parse arg input command
  15. input = upper(strip(input))
  16. address 'IMAGEENGINEER'
  17.  
  18. select  /* Required batch script commands */
  19.   when input = 'INFO' then    return get_info()
  20.   when input = 'CONFIG' then  return get_config(command)
  21.   when input = 'PROCESS' then return process_image(command)
  22.   otherwise do
  23.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  24.     return '<ERROR>'
  25.   end
  26. end
  27.  
  28. exit 0
  29.  
  30. /* Required "Get_info" procedure  ------------------------------------ */
  31. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  32.  
  33. get_info:
  34.   back = 'OK'
  35. return back
  36.  
  37. /* Required "Get_config" procedure  ---------------------------------- */
  38.  
  39. get_config:
  40.   parse arg '"'command'"'
  41.  
  42.   ADJ_H=20; SLICE_H=16; ADJ_V=20; SLICE_V=16
  43.   
  44.   if command ~= '' then parse var command '#'ADJTYPE ADJ_H SLICE_H ADJ_V SLICE_V .
  45.  
  46.   'IE_TO_FRONT'
  47.   
  48.   form = 'FORM "Adjust" " Accept | Cancel "',
  49.   ' TEXT,"Adjust cuts the image into slices which are adjusted horizontally or vertically"'
  50.   
  51.   if command = '' then form = form ||' RADIO,"Adjustment","Horizontally (Up & Down)|Vertically (Left & Right)|Both (First Horiz. then Vert.)|Both (First Vert. then Horiz.)",0'
  52.  
  53.   form = form ||' INTEGER,"Slice adjustment (Horiz)",1,1024,'strip(ADJ_H)',SLIDER',
  54.   ' INTEGER,"Slice width (Horiz)",1,1024,'strip(SLICE_H)',SLIDER',
  55.   ' INTEGER,"Slice adjustment (Vert)",1,1024,'strip(ADJ_V)',SLIDER',
  56.   ' INTEGER,"Slice width (Vert)",1,1024,'strip(SLICE_V)',SLIDER'
  57.   
  58.   form
  59.  
  60.   if command = '' then parse var result ok ADJTYPE ADJ_H SLICE_H ADJ_V SLICE_V .
  61.   else do
  62.     parse var result ok ADJ_H SLICE_H ADJ_V SLICE_V .
  63.     ADJTYPE = 'none'
  64.   end
  65.  
  66.   if ok = 0 then return '<ERROR>'
  67.  
  68.   back = '#'ADJTYPE ADJ_H SLICE_H ADJ_V SLICE_V
  69. return back
  70.  
  71. /* Required "Process_image" procedure  ------------------------------- */
  72.  
  73. process_image:
  74.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"'
  75.   parse var options '#'ADJTYPE ADJ_H SLICE_H ADJ_V SLICE_V .
  76.  
  77.   'OPEN' '"'src_image'"' '24'
  78.   if (RC ~= 0) then do
  79.     'IE_TO_FRONT'
  80.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  81.     return '<ERROR>'
  82.   end
  83.   else LoadImage = result
  84.  
  85.   'PROJECT_INFO' LoadImage 'WIDTH'
  86.   IW = RESULT
  87.   'PROJECT_INFO' LoadImage 'HEIGHT'
  88.   IH = RESULT
  89.  
  90.   'BRIGHTNESS' LoadImage '-255' 'INTENSITY'  /* Black image */
  91.   AdjImage = Result
  92.   
  93.   OrgImage = LoadImage
  94.   
  95.   UoD = -1
  96.   
  97.   if ADJTYPE=0 then call horiz()
  98.   if ADJTYPE=1 then call vert()
  99.   if ADJTYPE=2 then call horiz()
  100.   if ADJTYPE=3 then call vert()
  101.   
  102.   if (ADJTYPE=2|ADJTYPE=3) then do
  103.     OrgImage = AdjImage
  104.     'BRIGHTNESS' LoadImage '-255' 'INTENSITY'  /* Black image */
  105.     AdjImage = Result
  106.   end
  107.   
  108.   if ADJTYPE=2 then call vert()
  109.   if ADJTYPE=3 then call horiz()
  110.   
  111.   if (ADJTYPE=2|ADJTYPE=3) then 'CLOSE' OrgImage
  112.   
  113.   'CLOSE' LoadImage
  114.     
  115.   OutputImage = AdjImage
  116.     
  117.   if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1')
  118.   'SAVE_DATA' OutputImage '"'dst_image'"' '"'getclip('cfg_save_frmt')'"'
  119.   if (RC ~= 0) then do
  120.     'IE_TO_FRONT'
  121.     'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "'
  122.     return '<ERROR>'
  123.   end
  124.   'CLOSE' OutputImage
  125.  
  126.   back = 'OK'
  127. return back
  128.  
  129. /* Internal procedures  ---------------------------------------------- */
  130.  
  131. horiz:
  132.   do X = 0 to (IW+SLICE_H) by SLICE_H
  133.     
  134.     BX = X ; BY = 0 ; BEX = (X+SLICE_H-1) ; BEY = (IH-1)
  135.     if X >= IW then leave
  136.     if (X+SLICE_H) > (IW-1) then BEX = (IW-1)
  137.            
  138.     'CROP' OrgImage BX BY BEX BEY
  139.     CropImage=RESULT
  140.  
  141.     'MARK' CropImage 'PRIMARY'
  142.     'MARK' AdjImage 'SECONDARY'
  143.     'COMPOSITE' X (trunc(ADJ_H/2)*UoD) 'MIX 100'
  144.     Out = RESULT ; 'CLOSE' AdjImage ; 'CLOSE' CropImage ; AdjImage = Out
  145.  
  146.     if UoD = 1 then UoD = -1
  147.     else UoD = 1 
  148.   end
  149. return 'OK'
  150.  
  151. vert:
  152.   do Y = 0 to (IH+SLICE_V) by SLICE_V
  153.     
  154.     BX = 0 ; BY = Y ; BEX = (IW-1) ; BEY = (Y+SLICE_V-1)
  155.     if Y >= IH then leave
  156.     if (Y+SLICE_V) > (IH-1) then BEY = (IH-1)
  157.     
  158.     'CROP' OrgImage BX BY BEX BEY
  159.     CropImage=RESULT
  160.  
  161.     'MARK' CropImage 'PRIMARY'
  162.     'MARK' AdjImage 'SECONDARY'
  163.     'COMPOSITE' (trunc(ADJ_V/2)*UoD) Y 'MIX 100'
  164.     Out = RESULT ; 'CLOSE' AdjImage ; 'CLOSE' CropImage ; AdjImage = Out
  165.  
  166.     if UoD = 1 then UoD = -1
  167.     else UoD = 1 
  168.   end
  169. return 'OK'
  170.  
  171. /*******************************************************************/
  172. /* This is where control goes when an error code is returned by IE */
  173. /* It puts up a message saying what happened and on which line     */
  174. /*******************************************************************/
  175.  
  176. error:
  177. if RC=5 then do
  178.     IE_TO_FRONT
  179.     LAST_ERROR
  180.     'REQUEST "'||RESULT||'"'
  181. end
  182. else do
  183.     IE_TO_FRONT
  184.     LAST_ERROR
  185.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  186. end
  187. return '<ERROR>'
  188.